from django.shortcuts import render
from django.views.generic import View

from .models import Course

# Create your views here.


# 课程详情
class CourseDetailView(View):

    def get(self, request, course_id):
        course = Course.objects.get(id=int(course_id))

        course.click_nums += 1  # 增加课程点击数
        course.save()

        tag = course.tag
        relate_course = []
        if tag:
            relate_course = Course.objects.filter(tag=tag)[:1]

        return render(request, "course-detail.html", {
            "course": course,
            "relate_course": relate_course
        })
